<script type="text/javascript">
    $('form').submit(function() {
        $( '#content' ).val(editor.getData())
        $("#body").load($(this).attr("action"),$(this).serialize(),function(){$('#example').dataTable()});
        return false;
    });
</script>
<form action="index.php?page=CMS&action=saveContent" method="post">
    <table>
        <tr>
            <td>
                Content name
            </td>
            <td>
                <input type="text" name="name"  id="name" class="validate[required,length[0,50]]" <?php if (isset($content))
    echo "value ='" . $content->name . "' "; ?>/>
<?php if (isset($content))
    echo "<input type='hidden' name='id' id='id' value='{$content->id}'"; ?>
            </td>
        </tr>
        <tr>
            <td>
                Content Status
            </td>
            <td>
                <input type="radio" name="status" value="0" <?php if (isset($content)) {
    if ($content->status_ == 0)
        echo "checked";
} else
    echo "checked"; ?>/> closed &nbsp;&nbsp
                <input type="radio" name="status" value="1" <?php if (isset($content)) {
    if ($content->status_ == 1)
        echo "checked";
} ?> /> open
            </td>
        </tr>
        <tr>
            <td>
                Content Order
            </td>
            <td>
                <input type="text" name="order" id="order" class="validate[required,custom[integer]] text-input" <?php if (isset($content))
    echo "value='" . $content->order_ . "'"; else
    echo "value='0'"; ?>/>
            </td>
        </tr>
        <tr>
            <td>
                Content Section
            </td>
            <td>
                <select name="section" onchange="$('#subsectionContainer').load('index.php?page=CMS&action=getSubsections&id='+$(this).val())" validate[required]>
                        <option>Please select...</option>
<?php
foreach ($sections as $section) {
    $status = "";
    if ($section->id == $content->subsection->section->id) {
        $status = "selected";
    }
    echo ("<option {$status} value='{$section->id}'>{$section->name}</option> ");
}
?>
                </select>
            </td>
        </tr>
        <tr>
            <td>
                Content Subsection
            </td>
            <td id="subsectionContainer">
<?php
if (isset($content)) {
    echo "<select name='subsection' validate[required]>";
    foreach ($subsections as $subsection) {
        $status = "";
        if($content->subsection->id == $subsection->id )
            $status = "selected";
        echo "<option {$status} value='{$subsection->id}'>{$subsection->name}</option>";
    }
    echo "</select>";
}
?>
            </td>
        </tr>
        <tr>
            <td>
                Content
            </td>
            <td>
                <textarea cols="10" rows="10" name="content" id="content"><?php if (isset($content))
    echo $content->content ?></textarea>
            </td>
        </tr>

        <tr>
            <td>
                <input type="submit" value="save"/>
            </td>
        </tr>
    </table>
</form>
